﻿package com.athena.controller
{	
	import com.athena.vo.Chess;
	import com.athena.process.*;
	public class T_Controller {
		
		function T_Controller() { }
		
		public static function Search_Chess(hor : int, ver : int) {
			for (var i:int = 0; i < ProcessInTable.currTable.ArrPlayers[ProcessInTable.csOther].ArrChess.length; i++) 
			{
				if (ProcessInTable.currTable.ArrPlayers[ProcessInTable.csOther].ArrChess[i].Status == 1) continue ;
				if ((ProcessInTable.currTable.ArrPlayers[ProcessInTable.csOther].ArrChess[i].Hor == hor) && (ProcessInTable.currTable.ArrPlayers[ProcessInTable.csOther].ArrChess[i].Ver == ver)) {
					ProcessInTable.currTable.ArrPlayers[ProcessInTable.csOther].ArrChess_Movie[i].gotoAndStop(3) ;
					break ;
				}							
			}
		}
		
		public static function Valid(obj : Chess) {
			var hor : int = obj.Hor ;
			var ver : int = obj.Ver ;
			//Phai Tren
			if (((hor == 2) || (hor == 4) || (hor == 7) || (hor == 9)) && (ver < 7)) {
				if (ProcessInTable.ArrCheck[hor - 1][ver + 1] == 0) {
					if (ProcessInTable.ArrCheck[hor - 2][ver + 2] == 0) {
						Cocaro.mainStage_mc["Checked" + (hor - 2).toString() + (ver + 2).toString() + "_mc"].visible = true ;
						Cocaro.mainStage_mc["Checked" + (hor - 2).toString() + (ver + 2).toString() + "_mc"].over_mc.visible = false ;
					} else if (ProcessInTable.ArrCheck[hor - 2][ver + 2] != obj.Color)
						Search_Chess(hor - 2, ver + 2) ;
				}
			}
			//Trai Tren
			if (((hor == 2) || (hor == 4) || (hor == 7) || (hor == 9)) && (ver > 1)) {
				if (ProcessInTable.ArrCheck[hor - 1][ver - 1] == 0) {
					if (ProcessInTable.ArrCheck[hor - 2][ver - 2] == 0) {
						Cocaro.mainStage_mc["Checked" + (hor - 2).toString() + (ver - 2).toString() + "_mc"].visible = true ;
						Cocaro.mainStage_mc["Checked" + (hor - 2).toString() + (ver - 2).toString() + "_mc"].over_mc.visible = false ;
					} else if (ProcessInTable.ArrCheck[hor - 2][ver - 2] != obj.Color)
						Search_Chess(hor - 2, ver - 2) ;
				}
			}
			//Trai Duoi
			if (((hor == 2) || (hor == 0) || (hor == 7) || (hor == 5)) && (ver > 1)) {
				if (ProcessInTable.ArrCheck[hor + 1][ver - 1] == 0) {
					if (ProcessInTable.ArrCheck[hor + 2][ver - 2] == 0) {
						Cocaro.mainStage_mc["Checked" + (hor + 2).toString() + (ver - 2).toString() + "_mc"].visible = true ;
						Cocaro.mainStage_mc["Checked" + (hor + 2).toString() + (ver - 2).toString() + "_mc"].over_mc.visible = false ;
					} else if (ProcessInTable.ArrCheck[hor + 2][ver - 2] != obj.Color)
						Search_Chess(hor + 2, ver - 2) ;
				}
			}
			//Phai Duoi
			if (((hor == 2) || (hor == 0) || (hor == 7) || (hor == 5)) && (ver < 7)) {
				if (ProcessInTable.ArrCheck[hor + 1][ver + 1] == 0) {
					if (ProcessInTable.ArrCheck[hor + 2][ver + 2] == 0) {
						Cocaro.mainStage_mc["Checked" + (hor + 2).toString() + (ver + 2).toString() + "_mc"].visible = true ;
						Cocaro.mainStage_mc["Checked" + (hor + 2).toString() + (ver + 2).toString() + "_mc"].over_mc.visible = false ;
					} else if (ProcessInTable.ArrCheck[hor + 2][ver + 2] != obj.Color)
						Search_Chess(hor + 2, ver + 2) ;
				}
			}
		}
	}
}